import os
from config import *
import logging

class Document:
'''
一篇文档的对象
'''	
	def __init__(self, docnum):
		self.path = os.path.join(datapath, str(docnum))
		if not os.path.exists(self.path):
			logging.error('Not exists %s' % self.path) 
		f = open(self.path, 'r')
		lines = f.readlines()
		f.close()

		self.title = lines[0].split('=')[1].strip()
		self.abstract = lines[1].split('=')[1].strip()
		self.body = lines[2].split('=')[1].strip()
		
		self.comments = []

		for line in lines[4:]:
			self.comments.append(line)
	
	def getTitle(self):
		return self.title
	
	def getAbstract(self):
		return self.abstract

	def getBody(self):
		return self.body

	def getComments(self):
		return self.comments
	
	def getFulltext(self):
		return ' '.join([self.title, self.abstract, self.body])


if __name__ == '__main__':
	logging.basicConfig(filename='log', format='%(asctime)s %(levelname)s %(message)s',
			level=logging.DEBUG)
	paper = Document(38300)
	print paper.getTitle()
	print paper.getAbstract()
	print paper.getBody()
	print '\n'.join(paper.getComments())

	print '--------------------------------'
	print paper.getPassageModels()
